#ifndef MYMODEL_H
#define MYMODEL_H



#include <QAbstractTableModel>
#include <QVector>
#include <QString>

class MyModel : public QAbstractTableModel
{
    Q_OBJECT

public:
    explicit MyModel(QObject *parent = nullptr);
    ~MyModel();

    // 重写 QAbstractTableModel 的虚函数
    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
    Qt::ItemFlags flags(const QModelIndex &index) const override;

    // 自定义方法：用来设置数据
    void setData(const QVector<QVector<QString>> &data);

private:
    QVector<QVector<QString>> m_data;  // 存储表格数据
};

#endif // MYMODEL_H


